﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Reader.Libs.CONVERTER
{
    public class FileConverter
    {
        public string FullFilePath { get; set; }
        public string FileToSave { get; set; }
        public string Url;
        StringBuilder ConvertedResult = new StringBuilder();

        public void DeleteFiles()
        {
            if (File.Exists(FileToSave))
                File.Delete(FileToSave);
            if (File.Exists(FullFilePath))
                File.Delete(FullFilePath);
        }
        public StringBuilder ReadConvertedFile()
        {
            int Count = 0;
        ReadFileAgain:
            try
            {
                string ext = Path.GetExtension(FullFilePath);
                using (StreamReader reader = new StreamReader(FileToSave))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        ConvertedResult.Append(line);
                    }
                    reader.Dispose();
                }

            }
            catch (Exception ex)
            {
                System.Threading.Thread.Sleep(100);
                if (++Count == 3)
                {
                    throw ex;
                }
                goto ReadFileAgain;
            }
            return ConvertedResult;
        }

    }
}
